//
//  QYXCommentTableViewCell.m
//  OpenYourEyes
//
//  Created by dllo on 16/6/8.
//  Copyright © 2016年 Google AdWords. All rights reserved.
//

#import "QYXCommentTableViewCell.h"

@implementation QYXCommentTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
       
        self.headImageView = [[UIImageView alloc] init];
        self.headImageView.layer.cornerRadius = 15;
        self.headImageView.layer.masksToBounds = YES;
        [self.contentView addSubview:_headImageView];
        
        self.nameLabel = [[UILabel alloc] init];
        self.nameLabel.font = [UIFont fontWithName:@"FZLTZCHJW--GB1-0" size:15];
        self.nameLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_nameLabel];
        
        
        self.timeLabel = [[UILabel alloc] init];
        self.timeLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:13];
        self.timeLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_timeLabel];
        
        
        self.detailLabel = [[UILabel alloc] init];
        self.detailLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:13];
        self.detailLabel.numberOfLines = 0;
        self.detailLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_detailLabel];
        
        self.goodLabel = [[UILabel alloc] init];
        self.goodLabel.textColor = [UIColor whiteColor];
        self.goodLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:13];
        [self.contentView addSubview:_goodLabel];
        
        self.hotLabel = [[UILabel alloc] init];
        self.hotLabel.textColor = [UIColor whiteColor];
        self.hotLabel.font = [UIFont fontWithName:@"Lobster 1.4" size:13];
        [self.contentView addSubview:_hotLabel];
        
        self.lineView = [[UIView alloc] init];
        self.lineView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_lineView];


    }
    
    
    return self;
    
}


- (void)layoutSubviews

{
    [super layoutSubviews];
    
    self.headImageView.frame = CGRectMake(10, 10, 30, 30);
    self.nameLabel.frame = CGRectMake(self.headImageView.frame.origin.x + self.headImageView.frame.size.width + 10, 10, 175, 15);
    self.timeLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height + 5, self.nameLabel.frame.size.width, 15);
    self.detailLabel.frame = CGRectMake(self.timeLabel.frame.origin.x, self.timeLabel.frame.size.height + self.timeLabel.frame.origin.y + 5, self.contentView.frame.size.width - 30 - 10 - 10 - 20, 40);
    self.goodImageView.frame = CGRectMake(self.contentView.frame.size.width - 10 - 15, self.nameLabel.frame.origin.y, 15, 15);
    self.goodLabel.frame = CGRectMake(self.goodImageView.frame.origin.x - 5 - 30, self.nameLabel.frame.origin.y, 30, 15);
    self.hotLabel.frame = CGRectMake(self.contentView.frame.size.width - 10 - 50, self.goodLabel.frame.origin.y + self.goodLabel.frame.size.height + 5, 50, 15);
    self.lineView.frame = CGRectMake(self.nameLabel.frame.origin.x, self.bounds.size.height - 1, self.bounds.size.width, 1);

    
}


- (void)setModel:(QYXTopRankingModel *)model
{
    if (_model != model) {
        _model = model;
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:_model.commentModel.avatar] placeholderImage:kPlaceHolderImage];
        self.nameLabel.text = _model.commentModel.nickname;
    self.timeLabel.text = [self TimeBy:(NSInteger)_model.createTime];
    self.detailLabel.text = _model.message;
    self.goodImageView.image = [UIImage imageNamed:@"good"];
    self.goodLabel.text = [NSString stringWithFormat:@"%ld", _model.likeCount];
    if (_model.hot == true) {
        self.hotLabel.text = [NSString stringWithFormat:@"-Hot-"];
    }
}
    
}

- (NSString *)TimeBy:(NSInteger)number
{
    
    NSTimeInterval time = number + 28800;//因为时差问题要加8小时 == 28800 sec
    
    NSDate *detaildate= [NSDate dateWithTimeIntervalSince1970:time];
    
    //实例化一个NSDateFormatter对象
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ;
    
    //设定时间格式,这里可以设置成自己需要的格式
    
    [dateFormatter setDateFormat:@"HH:mm"];
    
    return [dateFormatter stringFromDate:detaildate];
    
}




@end
